﻿/* 
//1.遍历数组
int[] num = { 1, 2, 3, 4, 5 };
for(int i = 0; i < num.Length; i++){
    Console.WriteLine ( num[i] );
}

//2.增加数组
int[] arr1 = new int[5]{1, 2, 3, 4, 5};
int[] arr2 = new int[6];
for(int i=0; i < arr1.Length; i++){
    arr2[i] = arr1[i];
}
arr1 = arr2;
arr1[5] = 3;
for (int i = 0; i < arr1.Length; i++){
    Console.WriteLine(arr1[i]);
}

//3.查找元素
int []arr3 = new int[5]{1, 2, 3, 4, 5};
int a=3;
for(int i=0; i < arr3.Length; i++){
    if(arr3[i] == a){
        Console.WriteLine("{0}",i);
        break;
    }
}


//4.数组排序
int[] num1={50, 20, 80, 10, 30};
Array.Sort(num1);
for(int i = 0; i <num1.Length; i++){
    Console.Write(num1[i]);
}
//数组反转
Array.Reverse(num1);
for(int i = 0; i <num1.Length; i++){
    Console.Write(num1[i]);
}

//5.数组求和
int total = Sum(1, 2, 3, 4, 5);
Console.WriteLine("总和："+ total);
int Sum(params int[] nums){
    int sum = 0;
    foreach(int num in nums){
        sum+=num;
    }
    return sum;
}*/

//7_1
using System.Diagnostics;
using System.Text;
/*
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10000; i++){
    sb.Append(i).Append(", ");
}
string result = sb.ToString();
Console.WriteLine(result.Substring(0,50)+"...");

//7_2 插入删除
StringBuilder sb1 = new StringBuilder("Hello World");
sb1.Insert(5," C#");
Console.WriteLine(sb1.ToString());

sb1.Remove(5,3);
Console.WriteLine(sb1.ToString());

//7_3 替换与清空
sb1.Replace("Hello","C#");
Console.WriteLine(sb1.ToString());
sb1.Clear();
Console.WriteLine(sb1.Length);
*/

int iter=100000;
Stopwatch sw = new Stopwatch();
sw.Start();
string s="";
for(int i = 0; i < iter; i++){
    s+=i.ToString();
}
sw.Stop();
Console.WriteLine($"stringbuilder：{sw.ElapsedMilliseconds}ms");

sw.Restart();
StringBuilder sb = new StringBuilder();
for(int i = 0; i < iter; i++){
    sb.Append(i.ToString());
}
String result = sb.ToString();
sw.Stop();
Console.WriteLine($"string：{sw.ElapsedMilliseconds}ms");
